<template>
	<view class="wm">
		<view class="logo-box">
			<image v-if="settingk['logo']" class="logo" :src="settingImageUrl + settingk['logo']"></image>
		</view>
		<view class="list">
			<uni-list>
				<uni-list-item title="工作时间"  :rightText="settingk.workinghours" :border="border" />
				<uni-list-item title="一对一负责老师电话" note="(点击拨打)"  :rightText="teacherInfo.name+':'+teacherInfo.phone" :border="border" clickable  @click="telphone" />
			</uni-list>
		</view>
		<view class="wxqrcode">
			<view style="font-size: 25rpx;color: #999">长按识别</view>
			<image v-if="settingk.teacher_qrcode" :src="userteacherqrcodeImageUrl + teacherInfo.qrcode" class="qrcode" :show-menu-by-longpress='true' ></image>
			<view>一对一负责老师微信二维码</view>
		</view>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from "vuex"
    import settings from "../../store/settings";
	export default {
		data() {
			return {
				query_setting:{
					settings:"workinghours,logo,gf_tel,teacher_qrcode,weburl,gf_email"
				},
				border:false
			};
		},
		computed:{
			...mapState("m_user",["teacherInfo"]),
			...mapState("m_setting",['settings']),
			...mapGetters("m_setting",['settingk']),
			settingImageUrl(){
				return getApp().globalData.portImageUrl + "set/"
			},
			userteacherqrcodeImageUrl(){
				return getApp().globalData.portImageUrl + "userteahcerqrcode/"
			}
		},
		onLoad(){
			this.getSetting();
		},
		methods:{
			...mapMutations("m_setting",['addToSetting','updateStorageSize']),
			/**
			 * 获取后端配置保存到Storage中，如果在Storage中已经存在，则不在获取，如果需要刷新需要清理缓存才可以重新获取
			 */
			async getSetting(){
				//像数据库请求需要的数据
				let settings_arr = this.query_setting.settings.split(",");
				//判断data中要求加载的Setting是否存在，如果存在跳过请求，如果不存在则请求，并保存在vuex中，vuex会帮助我们保存到Storage中。
				for(let item in settings_arr){
					const findResult = this.settings.findIndex((x) => x.k == settings_arr[item]);
					if(findResult == -1){
						 const {data:res} = await uni.$http.post("Settings/getSettings",{settings:settings_arr[item]});
						 if(res.meta.status == 0) return uni.$showMsg("配置信息\""+settings_arr[item]+"\"请求失败");
						 this.addToSetting(res.data[0]);
					}else{
						continue
					}
				}
				this.updateStorageSize(uni.getStorageInfoSync().currentSize + "KB")
				
			},
			/**
			 * 点击拨打电话
			 */
			telphone(){
				uni.makePhoneCall({
					phoneNumber:this.teacherInfo.phone
				})
			},
			/**
			 * 点击复制邮箱地址
			 */
			copyemail(){
				uni.setClipboardData({
					data:this.settingk.gf_email,
					success:function(){
						uni.$showMsg("复制成功")
					},
				})
			},

		}
	}
</script>

<style lang="scss">
	page{
		background-color:#fff;
	}
	.logo-box{
		margin-top: 100rpx;
		display: flex;
		justify-content:center;
		.logo{
			width:300rpx;
			height:300rpx;
		}
	}
	.list{
		margin-top: 120rpx;
	}
	.wxqrcode{
		margin-top:150rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		color: #999;
		text-align: center;
	}
	.qrcode{
		width: 250rpx;
		height:250rpx;
		margin-bottom:10rpx;
		margin-top:10rpx;
	}

</style>
